package com.file;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileAttribute {
    public static void main(String[] args) {
//        File myFile = new File("D:" + File.separator +"FileIo" + File.separator + "panda.png");
//        if (myFile.exists()) {
//            System.out.printf("文件大小%s兆:%5.2f\n",myFile.length(),((double)myFile.length()/1024/1024));
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            System.out.printf("最后修改时间：%s、日期时间：%s\n",myFile.lastModified(),sdf.format(new Date(myFile.lastModified())));
//            System.out.printf("文件权限:可读：%s、可写：%s、可执行:%s\n",myFile.canRead(),myFile.canWrite(),myFile.canExecute());
//            System.out.printf("文件绝对路径%s\n",myFile.getAbsoluteFile());
//            System.out.printf("文件目录%s\n",myFile.getParent());
//            System.out.printf("文件名称%s\n",myFile.getName());
//            System.out.printf("路径类型文件夹：%s、文件：%s\n",myFile.isDirectory(),myFile.isFile());
//
//        }

        //19、20班
//        File myFile19 = new File("D:" + File.separator + "FileIo" + File.separator + "panda.png");
//        if (myFile19.exists()) {
//            System.out.printf("文件大小字节：%s，兆：%5.2f",myFile19.length(),((double)myFile19.length()/1024/1024));
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            System.out.printf("最后修改日期时间：%s、格式化后日期时间：%s\n",myFile19.lastModified(),sdf.format(new Date(myFile19.lastModified())));
//            System.out.printf("文件权限：可读：%s、可写：%s、可执行：%s\n",myFile19.canRead(),myFile19.canWrite(),myFile19.canExecute());
//            System.out.printf("文件绝对路径%s\n",myFile19.getAbsoluteFile());
//            System.out.printf("文件绝对路径字符串%s\n",myFile19.getAbsolutePath());
//            System.out.printf("文件名称%s\n",myFile19.getName());
//            System.out.printf("文件夹：%s，文件%s\n",myFile19.isDirectory(),myFile19.isFile());
//        }


        //指定目录的罗列
//        File file = new File("D:" + File.separator+"FileIo"+ File.separator);
//        infoFile(file);


//        File file19 = new File("D:" + File.separator+"FileIo" + File.separator);
//        infoFile19(file19);

        //outPutStream
//        File file1 = new File("D:" + File.separator + "FileIo" + File.separator + "out1.txt");
//        if (!file1.exists()) {
//            try {
//                file1.createNewFile();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        try {
//
//            OutputStream output1 = new FileOutputStream(file1);
//            String msg = "我要写的消息内容";
//            output1.write(msg.getBytes());
//            output1.close();
//            System.out.println("写入完成");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        //inputStream
//        File file1 = new File("D:" + File.separator + "FileIo" + File.separator + "out1.txt");
//        if (file1.exists()) {
//            try {
//                InputStream is = new FileInputStream(file1);
//                byte[] data = new byte[1024];
//                int len = is.read(data);
//                System.out.println("利用FileInputStream读取到的内容为:" + new String(data,0,len));
//                is.close();
//            } catch (FileNotFoundException e) {
//                e.printStackTrace();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }

        FileInputWhie fipw = new FileInputWhie();
        fipw.myReadFilebyWhie();
//        try {
//            fipw.encodePic();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

//        fipw.myReader();
//
//        fipw.ReaderByStream();

//        fipw.baseImg();
//        fipw.writerByChar();
//        fipw.readByChar();

    }

    public static void infoFile19(File file) {
        if (file.isDirectory()) {
            File[] list = file.listFiles((f1)->f1.isDirectory()?true:f1.getName().endsWith(".txt"));
            if (list != null) {
                for (File tmp :list) {
                    infoFile19(tmp);
                }
            }
        } else {
            System.out.println(file);
        }
    }

//    public static  void infoFile(File file) {
//        if (file.isDirectory()) {
//            File[] list = file.listFiles((f)->f.isDirectory()?true:f.getName().endsWith(".txt"));
//            if (list != null) {
//                for (File temp:list) {
//                    infoFile(temp);
//                }
//            }
//        }else {
//            System.out.println(file);
//        }
//
//    }


}
